var CommonJS = {
	// 验证码过期时间  5分钟-->300
	time_out: 300000,
    // 生成6位随机数
    generateMixed: function(){
        var res=""; 
        for(var i=0;i<6;i++) 
        { 
            res+=Math.floor(Math.random()*10); 
        }
         return res;
    },
    formatDate: function(timestamp){
    		if (timestamp == '') {
    			return '0'
    		}
	    var unixTimestamp =  new Date(timestamp * 1000)
	    return unixTimestamp.toLocaleString();
    },
    // 获取时间戳
    timestamp: function(){
        return Math.round(new Date().getTime()/1000);   
    },
    // 时间转 时间戳
    formatToTimestamp: function(stringTime){
		var timestamp2 = Date.parse(new Date(stringTime));
		timestamp2 = timestamp2 / 1000;
		return timestamp2;
    },
    // 获取当前时间 格式: 2017-11-02 14:19:23
    getNowFormatDate: function(e){
    		if(e){
    			var date = new Date(e);
    		}else{
    			var date = new Date();
    		}
//      var date = new Date();
        var year = date.getFullYear();
        var mouth = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        var ys = '-';
        var hs = ':';
        var ysy = ' ';
        if(mouth < 10){ /*月份小于10  就在前面加个0*/
            mouth = String(String(0) + String(mouth));
        }
        if(day < 10){ /*日期小于10  就在前面加个0*/
            day = String(String(0) + String(day));
        }
        if(hour < 10){ /*时小于10  就在前面加个0*/
            hour = String(String(0) + String(hour));
        }  
        if(minute < 10){ /*分小于10  就在前面加个0*/
            minute = String(String(0) + String(minute));
        }
        if(second < 10){ /*秒小于10  就在前面加个0*/
            second = String(String(0) + String(second));
        }
        
        var currentDate = String(year) + ys + String(mouth) + ys + String(day) + ysy + String(hour) + hs + String(minute) + hs + String(second);
        return currentDate;
    },

    //获取格式化时间-y-m-d
    getNowFormatDateDay: function(e)
    {
        if(e){
            var date = new Date(e);
        }else{
            var date = new Date();
        }
        var year = date.getFullYear();
        var mouth = date.getMonth() + 1;
        var day = date.getDate();
        var ys = '-';
        if(mouth < 10){ /*月份小于10  就在前面加个0*/
            mouth = String(String(0) + String(mouth));
        }
        if(day < 10){ /*日期小于10  就在前面加个0*/
            day = String(String(0) + String(day));
        }
        var currentDate = String(year) + ys + String(mouth) + ys + String(day);
        return currentDate;
    }
}
module.exports = CommonJS;